package com.hotel.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.hotel.entity.Livein;
import com.hotel.service.LiveinService;

@Controller
public class LiveinController {
	
	@Autowired
	private LiveinService liveinService;
	
	@RequestMapping(value = "checkIn")
	public ModelAndView checkIn(Livein live){
		ModelAndView mv = new ModelAndView();
		live.setInTime(new Date());
		SimpleDateFormat sf = new SimpleDateFormat("yyMMddhhmmss");
		live.setInNo(sf.format(new Date()));
		if(liveinService.insert(live)==1){
			mv.setViewName("redirect:liveinList.action");
		}else{
			mv.setViewName("forword:checkIn.action");
		}
		return mv;
	}
	@RequestMapping(value="liveinList")
	public ModelAndView liveinList(@RequestParam(value="pageNo",defaultValue="1")Integer pageNo,@RequestParam(value="pageSize",defaultValue="10")Integer pageSize){
		ModelAndView mv = new ModelAndView();
		List<Livein> liveins = liveinService.findAllLiveins(pageNo, pageSize);
		mv.addObject("liveins",liveins);
		mv.addObject("pageNo", pageNo);
		mv.addObject("pageSize", pageSize);
		mv.setViewName("views/livein/liveinlist");
		return mv;
	}
}
